var app = getApp();
var $ = require("../../utils/httpHelper.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    objarr: [],
    page: 1,
    pagesize: 20,
    totalpage: 0,//最大页数
    height: 0,
    nomore: true,
    del: false,
    room_id:'',
    class_id:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({ height: res.windowHeight})
      }
    })
    if (options.id){
      $.httpPost("member_info", { rd_session: app.globalData.userInfo.rd_session}, (data, err) => {
        if (data.data.room_id){
          wx.setStorageSync("room_id", data.data.room_id)
          this.setData({
            room_id:data.data.room_id,
            class_id: options.id
          })
          let params = {
            rd_session: app.globalData.userInfo.rd_session,
            class_id: options.id,
            room_id: data.data.room_id
          }
          $.httpPost("learn_channel_list", params, (data, err) => {
            this.setData({
              objarr: data.data.list,
              totalpage: data.data.total_page
            })
          })
        }
      })
      
    }
  },

  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        page_size: this.data.pagesize,
        room_id: this.data.room_id
      }
      $.httpPost("learn_channel_list", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },
  tolister(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/class/lister?channel_id=' + id+'&class_id='+this.data.class_id,
    })
  }
  
})